import React, { Component } from 'react'
import { connect } from 'react-redux'

class Home extends Component {
    render() {
        const { num, addNum } = this.props
        return (
            <div>
                <h3>
                    Home -- { num }
                </h3>
                <button onClick = {() => {
                    addNum(200)
                }}>+++</button>
            </div>
        )
    }
}

let mapState = (state) => {
    const { num } = state
    return {
        num
    }
}

let mapDispatch = (dispatch) => {
    return {
        addNum(num) {
            dispatch({ type: "ADD_NUM", num })
        }
    }
}

Home = connect(mapState, mapDispatch)(Home)

export default Home
